Release 10.1A: OpenEdge Development:
ProDataSets
Testing the Order ProDataSet
You can now put these statements together to create a procedure that defines, fills, and displays data from the ProDataSet
dsOrder. ProcedurefillDSOrder.pfollows this process:
- Includes the temp-table definitions and the ProDataSet definition you’ve already seen.
- Defines the queries for the
ttOrdertable and thettItemtable (the second one is used later).- Defines Data-Sources for all three temp-tables.
- Prepares the top-level query for the
ttOrdertable to bring inOrdernumber1.- Attaches all three Data-Sources to the ProDataSet buffers.
- Executes the
FILLmethod on the ProDataSet handle.- Detaches the Data-Sources from the ProDataSet buffers, as shown in the following example:
At this point
Ordernumber1, itsOrderLines, and theirItems, are all in the ProDataSet temp-tables.You can verify this simply by displaying some fields from them. For example:
When you run the procedure, you see the results of the
DISPLAYstatements—theOrder:
![]()
All of its
OrderLines:
![]()
And all the
Itemsused on any of thoseOrderLines:
![]()
This looks fine, but in fact, you were lucky you didn’t get an error when you ran it. Try changing the selection for the
Orderquery to fill allOrdersless than 10, as shown in this code snippet:
This will also fill all their
OrderLinesand all theItemsused on any of thoseOrderLines. Run the procedure and display theOrders,OrderLines, and finally theItems:
![]()
Some of the
Itemrecords, such asItem54, are represented more than once. This is because they are used in more than oneOrderLine. You probably don’t want them in yourttItemtable more than once. SinceMERGEis the defaultFILL-MODE, why didn’t Progress eliminate the duplicates?The answer is that you didn’t have an index on the
ttItemtable. Progress eliminates duplicates in a ProDataSet temp-table by relying on the internal indexing mechanism. Because this temp-table is not defined to beLIKEa database table, it does not inherit theItemtable’s indexes automatically. For Progress to eliminate duplicateItemsfrom this temp-table should they occur, you need a unique index on theItemNumfield. Add an index to the temp-table definition in the include filedsOrderTT.i, as shown:
Run the procedure again and the duplicate records are gone from the
ttItemtable. TheItemsnow come out in order as well, because of the index. This is the end of the display:Design tip: If there is a chance that a
![]()
FILLoperation might create duplicate records in a temp-table that you want eliminated, you must either define or inherit from the database schema a unique index for the temp-table, as done here for thettItemtable.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |